﻿namespace MainGame.GameScreens
{
    using System;

    using Microsoft.Xna.Framework;
    using Microsoft.Xna.Framework.Audio;
    using Microsoft.Xna.Framework.Content;
    using Microsoft.Xna.Framework.Graphics;

    using XGameLibrary.Controls;
    using XGameLibrary.ScreenManager;

    public class TitleScreen : BaseGameState
    {
        public TitleScreen(Game game, GameStateManager manager)
            : base(game, manager)
        {
        }

        private Texture2D BackgroundImage { get; set; }

        private LinkLabel StartLabel { get; set; }

        protected override void LoadContent()
        {
            ContentManager content = GameRef.Content;

            this.BackgroundImage = content.Load<Texture2D>(@"Images\Backgrounds\MainMenuScreen");

            base.LoadContent();

            this.StartLabel = new LinkLabel();
            this.StartLabel.Position = new Vector2(510, 630);
            this.StartLabel.Text = "Press ENTER to begin";
            this.StartLabel.Color = Color.White;
            this.StartLabel.TabStop = true;
            this.StartLabel.HasFocus = true;
            this.StartLabel.Selected += new EventHandler(this.StartLabel_Selected);

            this.ControlManager.Add(this.StartLabel);
        }

        public override void Update(GameTime gameTime)
        {
            this.ControlManager.Update(gameTime);

            base.Update(gameTime);
        }

        public override void Draw(GameTime gameTime)
        {
            this.GameRef.SpriteBatch.Begin();

            base.Draw(gameTime);

            this.GameRef.SpriteBatch.Draw(
                this.BackgroundImage,
                this.GameRef.ScreenRectangle,
                Color.White);

            this.ControlManager.Draw(this.GameRef.SpriteBatch);

            this.GameRef.SpriteBatch.End();
        }

        private void StartLabel_Selected(object sender, EventArgs e)
        {
            this.StateManager.PushState(this.GameRef.StartMenuScreen);
        }
    }
}
